<?

include_once "accesscontrol.php";

?>

<script src="prototype.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
function findSub(){
new Ajax.Request('findstate.php', {
	method: 'get',
	parameters:{						 
						 id: $F('country')
						},
	onLoading: function() { $('sub').update('Loading...') },
	onSuccess: function(transport){
						 if(transport.responseText){
						 	$('sub').update(transport.responseText);
						}
					}
				});
}
//-->
</SCRIPT>

<?

$q1 = "select plan, JS_number, JP_number, CompanyCountry from job_employer_info where ename = \"$_SESSION[ename]\" ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);


if(!empty($a1[plan]))
{
	$a11 = $a1[JP_number];

	$q2 = "select * from job_employer_info where ename = \"$_SESSION[ename]\" ";
	$r2 = mysql_query($q2) or die(mysql_error());
	$a2 = mysql_fetch_array($r2);

	if($a11 > 0)
	{

		if(isset($submit) && $submit == 'Post this job')
		{
			if (is_array($JobCategory))
			{
				$JobStr = implode("|" , $JobCategory);
			}
	
			$qc = "select job_id from job_post order by job_id desc";
			$rc = mysql_query($qc) or die(mysql_error());
			$ac = mysql_fetch_array($rc);
			$job_id = $ac[0] + 1;

			$position = strip_tags($position);
			$description = strip_tags($description);

			$EXday = date('d', mktime(0,0,0,0, date(d) + $_POST[exdays1], 0));
			$EXmonth = date('m', mktime(0,0,0, date(m), date(d) + $_POST[exdays1], 0));
			$EXyear = date('Y', mktime(0,0,0,date(m) ,date(d) + $_POST[exdays1], date(Y)));
			
			$dateAdded = date("Y/m/d : H:i:s");
		
			$q3 = "insert into job_post set
							job_id = \"$job_id\",
							ename = \"$_SESSION[ename]\", 
							CompanyCountry = \"$_POST[country]\",
							Company = \"$a2[CompanyName]\", 
							position = \"$position\", 
							JobCategory = \"$JobStr\", 
							short_desc = \"$s_desc\", 
							responsibilities = \"$respon\",  
							requirements = \"$require\",
							j_target = \"$j_target\", 
							salary = \"$salary\", 
							s_period = \"$s_period\",
							EXmonth = \"$EXmonth\",
							EXday = \"$EXday\",
							EXyear = \"$EXyear\",
							CompanyState = \"$_POST[state]\",
							createdTime = \"$dateAdded\" ";
			$r3 = mysql_query($q3) or die(mysql_error());

			$a11 = $a11 - 1;
			$q4 = "update job_employer_info set JP_number = JP_number - '1' where ename = \"$_SESSION[ename]\" ";
			$r4 = mysql_query($q4) or die(mysql_error());

			if($j_target == '1')
			{
				$clname = 'Student (High School)';
			}
			elseif($j_target == '2')
			{
				$clname = 'Student (undergraduate/graduate)';
			}
			elseif($j_target == '3')
			{
				$clname = 'Entry Level (less than 2 years of experience)';
			}
			elseif($j_target == '4')
			{
				$clname = 'Mid Career (2+ years of experience)';
			}
			elseif($j_target == '5')
			{
				$clname = 'Management (Manager/Director of Staff)';
			}
			elseif($j_target == '6')
			{
				$clname = 'Executive (SVP, EVP, VP)';
			}
			elseif($j_target == '7')
			{
				$clname = 'Senior Executive (President, CEO)';
			}


			$to = $a2[CompanyEmail];
			$subject = "Your Job post at $_SERVER[HTTP_HOST]";
			$message = "This is an automate sent copy of your Job post.\n\n Details:\n Job ID# $job_id \n Position: $position \n Category: $JobStr \n Description: $description \n Target: $clname \n Salary: $salary/$s_period \n Expire date: $EXmonth/$EXday/$EXyear\n\n\n To edit or delete this job, click here: http://$_SERVER[HTTP_HOST]$dir/employers/managejobs.php";
			$from = "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>";

			mail($to, $subject, $message, $from);

			echo "<br><br><br><br><br><br><center><span class=BlackLink>The job offer was posted successfully!<br><br><a href=\"JobInfo.php?id=$job_id\" class=BlackLink>preview</a> | \n\t <a href=\"EditJob.php?job_ed=$job_id\" class=BlackLink>edit</a> | \n\t<a href=\"PostJob.php\" class=BlackLink>continue</a></span><br><br><br> </center>";


			include_once("../footer.php");
			exit();
		}
		else
		{

		//echo "</table>";
		?>

		<SCRIPT LANGUAGE="JavaScript">

		function checkFields() {
		missinginfo = "";

		if (document.form.position.value == "") {
		missinginfo += "\n     -  Position";
		}
		if (document.form.description.value == "") {
		missinginfo += "\n     -  Description";
		}
		if (document.form.salary.value == "") {
		missinginfo += "\n     -  Salary";
		}
	

		if (missinginfo != "") {
		missinginfo ="_____________________________\n" +
		"You failed to correctly fill in your:\n" +
		missinginfo + "\n_____________________________" +
		"\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
		}
		else return true;
		}
		</script>

<span class=HeaderClass>Post Job</span><br><br>
		<table width=460 border="0" align=center cellpadding="0" cellspacing="5" class=BlackText>
	
		<tr>
		  <td colspan=2 align=center class=HeaderClass>&nbsp;</td>
		  </tr>
		<tr><td colspan=2 align=center class=HeaderClass>Use this form to post a new job offer:</td></tr>
		<tr>
		  <td colspan=2 align=center class=HeaderClass>&nbsp;</td>
		  </tr>
		<form method=post name=form onSubmit="return checkFields();">
		<tr><td align=left>Position:</td>
	
		<td>
		<input type=text name=position>		</td>
		</tr>

<tr>
	<td align=left>Job State: </td>
	<td>
		<div id="sub">
			<select name=state>
				<option value=" ">Select</option>
<?php
foreach ($state as $key => $value){
?>
		<option value="<?=$value?>"><?=$value?></option>
<?
}
?>	
			</select>
		</div></td>	
</tr>

<tr>
	<td align=left>Job location: </td>
	<td><?=select_country($country, "country");?></td>	
</tr>

		
		<tr>
		<td valign=top align=left>
		Job Category: <br>		</td>

		<td valign=top><?=job_categories("", "JobCategory[]", "multiple size=5");?></td>
		<tr><td valign=top align=left>Short Description: <br>
		  (requirement need,<br> vacancy availability)</td>
		<td><textarea rows=6 cols=35 name=s_desc></textarea></td>
		</tr>
		
		<tr><td valign=top align=left>Responsibilities: </td>
		<td><textarea rows=6 cols=35 name=respon></textarea></td>
		</tr>
		
		<tr><td valign=top align=left>Requirements:</td>
		<td><textarea rows=6 cols=35 name=require></textarea></td>
		</tr>

		<tr>
		<td align=left>Target: </td>

		<td>
		<select name="j_target">
		<option value=""> </option>
		<OPTION VALUE="1">Student (High School)</OPTION>
		<OPTION VALUE="2">Student (undergraduate/graduate)</OPTION>
		<OPTION VALUE="3">Entry Level (less than 2 years of experience)</OPTION>
		<OPTION VALUE="4">Mid Career (2+ years of experience)</OPTION>
		<OPTION VALUE="5">Management (Manager/Director of Staff)</OPTION>
		<OPTION VALUE="6">Executive (SVP, EVP, VP)</OPTION>
		<OPTION VALUE="7">Senior Executive (President, CEO)</OPTION>
		</select>		</td>
		</tr>
	
		<tr><td align=left>Salary: </td>
		<td>
		<input type=text name=salary size=11> 
		<select name=s_period>
		<option value=Yearly> Yearly </option>
		<option value=Monthly>Monthly </option>
		</select>		</td></tr>

		<tr>
		<td align=left>
		This offer expire after:		</td>

		<td>
		<select name=exdays1>
		<option value=30> 30 </option>
		<option value=60> 60 </option>
		<option value=90> 90 </option>
		</select>
		 days.		</td>
		</tr>


		<tr>
			<td align="left"></td>
			<td>
				<input type=submit name=submit value="Post this job">			</td>
		</tr>
		</table>
		</form>
		<?
		}
	}
	else
	{
		include "pay1.php";
	}
}
else
{
	include "pay1.php";
}

include_once("../footer.php");
?>
